<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:import href="base-template.imp.xsl" />
	
	<xsl:template name="jscript">
		<script>
		
			var Models = new Array();
			
			<xsl:for-each select="//page/all-models/CarModel">
				var Mod = new Object();
				Mod.id = <xsl:value-of select="@id" />;
				Mod.name = '<xsl:value-of select="@name" />';
				Mod.developer = <xsl:value-of select="Developer/@id" />;
				Models.push(Mod);
			</xsl:for-each>			
			

		</script>
	</xsl:template>
	
	<xsl:output encoding="UTF-8" method="html" saxon:character-representation="native" xmlns:saxon="http://saxon.sf.net/"/>
	<xsl:template name="content">
		<xsl:call-template name="jscript" />
		<div class="title">Добавление объявления</div>
		<form name="car-info" method="post" action="/admin/cars/add/check" enctype="multipart/form-data">
		<table>
			<tr>
				<td class="text" width="200px">Производитель: </td>
				<td>
					<select name="developer" style="width: 100%" onchange="reloadModels()" id="devs">
						<xsl:for-each select="//page/all-developers/CarDeveloper">
							<option value="{@id}"><xsl:value-of select="@name" /></option>
						</xsl:for-each>
					</select>				
					
					<div style="width:30em; height:1px"/>
				</td>
			</tr>
			<tr>
				<td class="text">Модель: </td>
				<td><select name="model" id="mods" style="width:100%">
						<option value="0">-- Сначала выбирите производителя --</option>
					 </select>
				</td>
			</tr>
			<tr>
				<td class="text">Объем двигателя: см<sup>3</sup></td>
				<td><input type="text" name="enginev" /></td>
			</tr>
			<tr>
				<td class="text">Год выпуска:</td>
				<td><input type="text" name="year" /></td>
			</tr>
		

			<tr>
				<td class="text">Пробег: км.</td>
				<td><input type="text" name="path" /></td>
			</tr>
			<tr>
				<td class="text">Цена: $</td>
				<td><input type="text" name="price" /></td>
			</tr>
			<tr>
				<td class="text">Цвет: </td>
				<td><input type="text" name="color" /></td>
			</tr>
			<tr>
				<td class="text">Состояние:</td>
				<td>
					<select name="state">
						<xsl:for-each select="//page/all-states/state">
							<option value="{@id}"><xsl:value-of select="@name" /></option>
						</xsl:for-each>
					</select>
				</td>
			</tr>
			<tr>
				<td class="text">Описание: </td>
				<td><textarea name="description" style="width:100%"/></td> 
			</tr>
			
			<tr>
				<td class="text"  >Изображение(JPEG, 114х90):</td>
				<td><input type="file" name="small_img" /></td>
			</tr>				
			
			<tr id="elite_img" >
				<td class="text"  >Изображение для "элитного" автомобиля(JPEG, 235х100):</td>
				<td><input type="file" name="big_img" /></td>
			</tr>					
						
			<xsl:choose>
				<xsl:when test="//page/logined/@status=2">
					<tr>
						<td class="text">Разместить объявление: </td>
						<td>
							<input type="radio" name="status" value ="1" checked="checked" onclick="showEliteImg()"/>В салоне
							<![CDATA[&nbsp;&nbsp;&nbsp;]]>
							<input type="radio" name="status" value ="2" onclick="hideEliteImg()"/>На заказ
						</td> 
					</tr>									
				</xsl:when>
				<xsl:otherwise>
					<input type="hidden" name="status" value ="3" />
				</xsl:otherwise>
			</xsl:choose>

			<tr>
			<td><input type="submit" value="OK" /></td>
			</tr>
		</table>
		</form>		
		<![CDATA[ 
		<script>
			var DevEl = document.getElementById('devs');
			
			var ModEl = document.getElementById('mods');
				
			var actulalModels = new Array();
			
			function reloadModels(){	
				DevEl = document.getElementById('devs');
				var actulalModels = new Array();	
				for(var i=0; i<Models.length; i++)
					if(Models[i].developer == DevEl.value)
						actulalModels.push(Models[i]);
				ModEl.innerHTML='';		
				for(var i=0; i<actulalModels.length; i++){
					
					var newO = document.createElement("option");
					newO.value = actulalModels[i].id;
					newO.innerHTML = actulalModels[i].name;
					ModEl.appendChild(newO);
					//ModEl.innerHTML+='<OPTION value="'+actulalModels[i].id+'">'+actulalModels[i].name+'</OPTION>';						
				}
			}
			
			function showEliteImg(){
				document.getElementById('elite_img').style.display="";
			}
			
			function hideEliteImg(){
				document.getElementById('elite_img').style.display="none";
			}			
		]]>	
		<xsl:if test="not(//page/logined/@status=2)">
			hideEliteImg();
		</xsl:if>
		<![CDATA[	reloadModels();
				
		</script>
		
		]]>
	</xsl:template>
		

</xsl:stylesheet>	